<?php
class ManageBoothMenu extends Module
{
	var $hotel = array();
	
	function ManageBoothMenu($row)
	{
		Module::Module($row);

		$id 		= Url::getInt("booth_id");
        
        if($id)
        {
        	$this->hotel = Db_Booth::getBoothById($id);
        }
        
        if(!$this->hotel || $this->hotel['status'] == -1)
        {
        	Url::redirect("manage_booth");
        }
        
        #############################################################################
        //Check quyền
		if(!User::have_permit("hotel_edit"))
        {
        	if(!Db_Hotel::have_permit_manage($this->hotel, User::id()))
	        {
	        	Url::access_denied();
	        }
        }
        #############################################################################
        
		switch(Url::get('cmd'))
   		{
   			case 'edit':
                CGlobal::$website_title = "Sửa thực đơn";
                
                require_once "forms/ManageBoothMenuEdit.php";
                $this->add_form(new ManageBoothMenuEditForm());
                
                break;
            case 'add':
                CGlobal::$website_title = "Thêm thực đơn";
                
                require_once "forms/ManageBoothMenuAdd.php";
                $this->add_form(new ManageBoothMenuAddForm);
                
                break;
                
          	case 'delete':
          		$id = Url::getInt('id', 0);
                
                if($id)
                {
                	$room = Db_BoothMenu::getById($id);
                	
	                if($room && $room['status'] != -1 && $room['booth_id'] == $this->hotel['id'] && User::have_permit("hotel_edit"))
                	{
	                	Db_BoothMenu::delBoothMenuById($id);
	                }
                }
                
                $href = Url::get('href');
            
	            if($href)
	            {
	            	Url::redirect_url($href);
	            }
	            else 
	            {
	            	Url::redirect_current(array('booth_id'));
	            }
                
                break;
                
            case 'show':
                $status=1;
                
            case 'hide':
            	$href = Url::get('href');
            	//echo $href;exit;
            	 
                if(!isset($status))
                {
                    $status		=	2;
                }
                
                $id = Url::getInt('id', 0);
                
                if($id)
                {
                	$room = Db_BoothMenu::getById($id);
                	
                	if($room && $room['status'] != -1 && $room['status'] != $status && $room['booth_id'] == $this->hotel['id'] && (User::have_permit("hotel_edit")))
                	{
                		Db_BoothMenu::updateSatus($id, $status);
                	}
                }
                
                $href = Url::get('href');
            
	            if($href)
	            {
	            	Url::redirect_url($href);
	            }
	            else 
	            {
	            	Url::redirect_current(array('booth_id'));
	            }
                
                break;
            case 'restore':
                $id = Url::getInt('id', 0);
                
                if($id)
                {
                	$room = Db_BoothMenu::getById($id);
                	
                	if($room && $room['status'] == -1 && $room['booth_id'] == $this->hotel['id'] && User::have_permit("hotel_edit"))
                	{
                		Db_BoothMenu::updateSatus($id, 1);
                	}
                }
                
                $href = Url::get('href');
            
	            if($href)
	            {
	            	Url::redirect_url($href);
	            }
	            else 
	            {
	            	Url::redirect_current(array('hotel_id'));
	            }
	            
                break;    
            default:
                require_once "forms/ManageBoothMenuList.php";
				$this->add_form(new ManageBoothMenuListForm());
                break;
		}
	}
        static function permission(){
        return array(
                    'room_admin' => "Quản trị thực đơn"
                );
    }
}
?>